[#assign shiro=JspTaglibs["/WEB-INF/tld/shiro.tld"] /]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${message("admin.order.edit")} - 766 SMART HOME</title>
<meta name="author" content="BIZ Team" />
<meta name="copyright" content="BIZ" />
<link href="${base}/resources/admin/css/common.css" rel="stylesheet" type="text/css" />
<link href="${base}/resources/admin/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${base}/resources/admin/js/jquery.js"></script>
</head>
<body>
	<div class="path">
		<a href="${base}/admin/common/index.jhtml">${message("admin.path.index")}</a> &raquo; ${message("admin.order.edit")}
	</div>
	<input id="basePath" value="${base}" type="hidden"/>
	<ul id="tab" class="tab">
		<li>
			<input type="button" value="${message("admin.order.orderInfo")}" />
		</li>
		<li>
			<input type="button" value="${message("admin.order.productInfo")}" />
		</li>
	</ul>
	<form id="inputForm" action="updateScheme.jhtml" method="post">
		<input type="hidden" id="orderId" name="id" value="${order.id}" />
		<input type="hidden" id="schemeType" value="${order.schemeType}" />
		<input type="hidden" id="schemeStatus" value="${order.schemeStatus}" />
		<input type="hidden" name="consignee" value="${order.consignee}" />
		<input type="hidden" name="point" value="${order.point}" />
		<input type="hidden" id="update_order_item_schemes" name="update_order_item_schemes" />
		<input type="hidden" id="order_isTehui"  value="${order.isTehui}" />
		<input type="hidden" id="order_isChange" value="${order.isChange}" />
		<input type="hidden" id="order_outNumber" value="${order.outNumber}" />
		<input type="hidden" id="order_inNumber" value="${order.inNumber}" />
		<table class="input tabContent">
			<tr>[#-- 订单编号、合同编号，订单创建日期  --]
				<th>
					${message("Order.sn")}:
				</th>
				<td width="360">
					${order.sn}
				</td>
				<th>
					${message("Order.contract")}:
				</th>
				<td>
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							<input type="text" name="contract" class="text" value="${order.contract}"/>
						[/@shiro.hasPermission]
					[#else]
						${order.contract}
						<input type="hidden" name="contract" value="${order.contract}"/>
					[/#if]
				</td>
				<th>
					工程编号:
				</th>
				<td>
					[#if order.schemeStatus==6]
						[@shiro.hasPermission name = "admin:orderAudit"]
							<input type="text" name="engineering" class="text" value="${order.engineering}"/>
						[/@shiro.hasPermission]
					[#else]
						<input type="hidden" name="engineering" value="${order.engineering}"/>
					[/#if]
				</td>
			</tr>
			<tr>[#-- 订单类型 ，方案状态、方案支付状态 --]
				<th>
					${message("Order.orderType")}:
				</th>
				<td>
					${message("Project.type."+ order.orderType)}
				</td>
				<th>
					${message("Order.schemeStatus")}:
				</th>
				<td>
					${message("Order.OrderStatus." + order.schemeStatus)}
					[#if order.expired]
						<span title="${message("Order.expire")}: ${order.expire?string("yyyy-MM-dd HH:mm:ss")}">(${message("admin.order.hasExpired")})</span>
					[#elseif order.expire??]
						<span title="${message("Order.expire")}: ${order.expire?string("yyyy-MM-dd HH:mm:ss")}">(${message("Order.expire")}: ${order.expire})</span>
					[/#if]
				</td>
				<th>
					${message("Order.schemePaymentStatus")}
				</th>
				<td>
					${message("Order.schemePaymentStatus."+order.schemePaymentStatus)}
				</td>
			</tr>
			<tr>[#-- 面积，门店调整面积  --]
				<th>
					${message("Order.schemeArea")}:
				</th>
				<td>
					${order.schemeArea}${message("Order.areaUnit")}
				</td>
				<th>
					${message("Order.shopSchemeArea")}:
				</th>
				<td>
					[#if order.schemeStatus==1]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							<input type="text" class="text" id="order_scheme_shop_area" name="shopSchemeArea" value="${order.shopSchemeArea}"/>${message("Order.areaUnit")}
						[/@shiro.hasPermission]
					[#else]
						${order.shopSchemeArea}/${message("Order.areaUnit")}
						<input type="hidden" name="shopSchemeArea" value="${order.shopSchemeArea}"/>
					[/#if]
				</td>
				<th class="font-bold">
					${message("Order.amount")}:
				</th>
				<td id="order_amount_td">
					${currency(order.amount, true)}
				</td>
			</tr>
			<tr>[#-- 面积，门店调整面积  --]
				<th>
					辅材价格:
				</th>
				<td>
					${currency(order.auxiliaryUnitPrice, true)} /${message("Order.areaUnit")}
				</td>
				<th>
					安装费:
				</th>
				<td>
					${currency(order.installCost, true)}/${message("Order.areaUnit")}
				</td>
				<th>
					${message("Order.quantity")}:
				</th>
				<td>
					${order.quantity}
				</td>
			</tr>
			<tr>
				<th>
					${message("Order.paymentMethod")}:
				</th>
				<td>
					[#if order.schemeStatus==1]
					[@shiro.hasPermission name = "admin:orderAdjust"]
						<select name="paymentMethodId">
							<option value="">${message("admin.common.choose")}</option>
							[#list paymentMethods as paymentMethod]
								<option value="${paymentMethod.id}"[#if paymentMethod == order.paymentMethod] selected="selected"[/#if]>${paymentMethod.name}</option>
							[/#list]
						</select>
					[/@shiro.hasPermission]
					[#elseif order.schemeStatus==7]
					[@shiro.hasPermission name = "admin:tailPayment"]
						<select name="paymentMethodId">
							<option value="">${message("admin.common.choose")}</option>
							[#list paymentMethods as paymentMethod]
								<option value="${paymentMethod.id}"[#if paymentMethod == order.paymentMethod] selected="selected"[/#if]>${paymentMethod.name}</option>
							[/#list]
						</select>
					[/@shiro.hasPermission]
					[#else]
					${order.paymentMethod.name}	
					<input type="hidden" name="paymentMethodId" value="${order.paymentMethod.id}"/>
					[/#if]
				</td>
				<th>
					${message("Order.freight")}:
				</th>
				<td>
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							￥<input type="text" id="order_freight" onkeyup="calculate_scheme()" name="freight" class="text" value="${currency(order.freight, false)}"/>
						[/@shiro.hasPermission]
					[#else]
						${currency(order.freight, true)}
						<input type="hidden" name="freight" value="${order.freight}"/>
					[/#if]
				</td>
				<th>
					${message("Order.fee")}:
				</th>
				<td>
					${currency(order.fee, true)}
				</td>
			</tr>
			<tr>
				<th>
					${message("Order.promotionDiscount")}:
				</th>
				<td>
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							￥<input type="text" id="order_promotionDiscountScheme" onkeyup="calculate_scheme()" class="text" name="promotionDiscountScheme" value="${currency(order.promotionDiscountScheme, false)}" />
						[/@shiro.hasPermission]
					[#else]
						${currency(order.promotionDiscountScheme, true)}
						<input type="hidden" id="order_promotionDiscountScheme" name="promotionDiscountScheme" value="${order.promotionDiscountScheme}"/>
					[/#if]
					
				</td>
				<th>
					${message("admin.common.createDate")}:
				</th>
				<td>
					${order.createDate?string("yyyy-MM-dd HH:mm:ss")}
				</td>
				<th class="font-bold">
					${message("Order.percent")}:
				</th>
				<td [#if (order.percent<60)]class="red"[/#if] id="percent">
					${order.percent?string("0.##")}%
				</td>
			</tr>
			[#-- 支付状态，剩余应支付、已付金额  --]
			<tr>
				<th>
					附加金额:
				</th>
				<td>
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							￥<input type="text" id="otherMoneyCheck" name="otherMoney" class="text" value="${currency(order.otherMoney, false)}" maxlength="200" />
						[/@shiro.hasPermission]
					[#else]
						${currency(order.otherMoney, true)}
						<input type="hidden" name="otherMoney" value="${order.otherMoney}" />
					[/#if]
				</td>
				<th class="font-bold">
					${message("Order.surplusMoney")}:
				</th>
				<td id="surplusMoney">
						￥${currency(order.percentPrice, false)}
				</td>
				<th class="font-bold">
					${message("Order.payOff")}:
				</th>
				<td id="alreadyPaid">
					${currency(order.percentPricePaid, true)}
				</td>
			</tr>
			<tr>
				<th>
					${message("Order.shippingMethod")}:
				</th>
				<td>
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							<select name="shippingMethodId">
								<option value="">${message("admin.common.choose")}</option>
								[#list shippingMethods as shippingMethod]
									<option value="${shippingMethod.id}" info="${order.shippingMethod.id}" [#if shippingMethod.id == order.shippingMethod.id]] selected="selected"[/#if]>${shippingMethod.name}</option>
								[/#list]
							</select>
						[/@shiro.hasPermission]
					[#else]
						[#if order.shippingMethod??]
							<input type="hidden" name="shippingMethodId" value="${order.shippingMethod.id}"/>
							${order.shippingMethod.name}
						[/#if]
					[/#if]
				</td>
				<th>
					${message("Order.shippingStatus")}:
				</th>
				<td>
					${message("Order.ShippingStatus." + order.shippingStatus)}
				</td>
				<th>
					${message("Member.username")}:
				</th>
				<td>
					${order.member.username}
				</td>
			</tr>
			<tr>
				<th>
					${message("Order.consignee")}:
				</th>
				<td>
					${order.consignee}
				</td>
				<th>
					${message("Order.phone")}:
				</th>
				<td>
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							<input type="text" name="phone" class="text" value="${order.phone}" maxlength="200" />
						[/@shiro.hasPermission]
					[#else]
						${order.phone}
						<input type="hidden" name="phone" value="${order.phone}"/>
					[/#if]
				</td>
				<th>
					${message("Order.zipCode")}:
				</th>
				<td>
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							<input type="text" name="zipCode" class="text" value="${order.zipCode}" maxlength="200" />
						[/@shiro.hasPermission]
					[#else]
						${order.zipCode}
						<input type="hidden" name="zipCode" value="${order.zipCode}"/>
					[/#if]
				</td>
			</tr>
			<tr>
				<th>
					${message("Order.area")}:
				</th>
				<td>
					<span class="fieldSet">
						<input type="hidden" id="areaId" name="areaId" value="${(order.area.id)!}" treePath="${(order.area.treePath)!}" />
					</span>
				</td>
				<th>
					${message("Order.address")}:
				</th>
				<td>
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							<input type="text" name="address" class="text" value="${order.address}" maxlength="200" />
						[/@shiro.hasPermission]
					[#else]
						${order.address}
						<input type="hidden" name="address" value="${order.address}"/>
					[/#if]
					
				</td>
				<th>
					${message("Order.community")}:
				</th>
				<td>
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							<input type="text" name="community" class="text" value="${order.community}" maxlength="50" />
						[/@shiro.hasPermission]
					[#else]
						${order.community}
						<input type="hidden" name="community" value="${order.community}"/>
					[/#if]
				</td>
			</tr>
			<tr>
				<th>
					${message("Order.houseType")}:
				</th>
				<td>
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							<input type="text" name="houseType" class="text" value="${order.houseType}" maxlength="50" />
						[/@shiro.hasPermission]
					[#else]
						${order.houseType}
						<input type="hidden" name="houseType" value="${order.houseType}"/>
					[/#if]
					
				</td>
				<th>
					下单门店:
				</th>
				<td>
					[#if order.shops??]
						${order.shops.shopsName}
					[/#if]
				</td>
				<th>
					服务门店:
				</th>
				<td>
					[#if order.serviceShops??]
						${order.serviceShops.shopsName}
					[/#if]
				</td>
				
			</tr>
			<tr>
				<th>
					${message("Order.memo")}:
				</th>
				<td  colspan="5">
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							<input type="text" name="memo" class="text" value="${order.memo}" maxlength="200" />
						[/@shiro.hasPermission]
					[#else]
						${order.memo}
					[/#if]
					<input type="hidden" name="isInvoice" value="${order.isInvoice}" />
				</td>
			</tr>
			<tr>
				<th>
					${message("Order.backCuse")}:
				</th>
				<td colspan="5">
					${order.backCuse}
					<input type="hidden" name="isInvoice" value="false" />
				</td>
			</tr>
			<tr>
				<th>
					${message("Order.canselCause")}:
				</th>
				<td colspan="5">
					${order.canselCause}
				</td>
			</tr>
		</table>
		<table id="orderItemTable" class="input tabContent">
					<tr>
						<td colspan="7">
							<input type="button" class="button" info="${order.schemeStatus}" info="${order.schemeStatus}" [#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4][#else]disabled="disabled"[/#if] value="新增主材" id="addOrderItem_scheme" />
							<input type="button" class="button" [#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4][#else]disabled="disabled"[/#if] value="新增赠品" id="addOrderItem_scheme_gift" />
							[#if order.schemeType==14][#--智能暖气--] 
								<input type="checkBox" [#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4][#else]disabled="disabled"[/#if] onclick="checkBoxScheme(this)" name="isTemperature" [#if order.isTemperature] checked=checked value="true" [#else] value="false" [/#if] id="order_isTemperature" />启用电热执行器及温控面板
								<input type="checkBox" [#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4][#else]disabled="disabled"[/#if] onclick="checkBoxScheme(this)" name="isDissipate" [#if order.isDissipate] checked=checked value="true" [#else] value="false" [/#if]  id="order_isDissipate" />启用卫浴散热器
							[#elseif order.schemeType=105][#--智能空调--]
								<input type="checkBox" [#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4][#else]disabled="disabled"[/#if] onclick="checkBoxScheme(this)" name="isPromote" [#if order.isPromote] checked=checked value="true" [#else] value="false" [/#if] id="order_isPromote" />启用提升泵
								<input type="checkBox" [#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4][#else]disabled="disabled"[/#if] onclick="checkBoxScheme(this)" name="isController" [#if order.isController] checked=checked value="true" [#else] value="false" [/#if] id="order_isController" />启用控制器
							[/#if]
						</td>
					</tr>
			[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
				[@shiro.hasPermission name = "admin:orderAdjust"]
				[/@shiro.hasPermission]
			[#else]
				[#if order.schemeType==24][#--智能暖气--]
					<input type="checkBox" [#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4][#else]disabled="disabled"[/#if] name="isTemperature" [#if order.isTemperature] checked=checked value="true" [#else] value="false" [/#if] style="display:none;"/> 
					<input type="checkBox" [#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4][#else]disabled="disabled"[/#if] name="isDissipate" [#if order.isDissipate] checked=checked value="true" [#else] value="false" [/#if] style="display:none;"/> 
				[#elseif order.schemeType=105][#--智能空调--]
					<input type="checkBox" [#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4][#else]disabled="disabled"[/#if] name="isPromote" [#if order.isPromote] checked=checked value="true" [#else] value="false" [/#if] style="display:none;"/>
					<input type="checkBox" [#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4][#else]disabled="disabled"[/#if] name="isController" [#if order.isController] checked=checked value="true" [#else] value="false" [/#if]  style="display:none;"/>
				[/#if]
			[/#if]
			<tr class="title">
				<th>
					${message("Product.sn")}
				</th>
				<th>
					${message("Product.name")}
				</th>
				<th>
					品牌
				</th>
				<th>
					规格
				</th>
				<th>
					数量
				</th>
				<th>
					替换编号
				</th>
				<th>
					替换名称
				</th>
				<th>
					替换品牌
				</th>
				<th>
					替换规格
				</th>
				<th>
					差价
				</th>
				<th>
					${message("admin.common.handle")}
				</th>
			</tr>
			[#list order.orderItems as orderItem]
				<tr [#if orderItem.name=="电热执行器" || orderItem.name="温控面板" ] class="orderItemTr isTemperatureTr" style="display:none;" [#elseif orderItem.name=="卫浴散热器"] class="orderItemTr isDissipateTr" style="display:none;" [#elseif orderItem.name=="提升泵"] class="orderItemTr isPromoteTr" style="display:none;" [#elseif orderItem.name="控制器"]  class="orderItemTr isControllerTr" style="display:none;"  [#else] class="orderItemTr"  [/#if] [#if orderItem.coefficient??] isCoefficient="true" [/#if]>
					<td>
						<input type="hidden" class="checkSchemeId" name="orderItems[${orderItem_index}].id" value="${orderItem.id}" />
						<input type="hidden" name="orderItems[${orderItem_index}].sn" class="orderItemSn" value="${orderItem.sn}" />
						<input type="hidden" class="checkSchemePrice" quantity="${orderItem.quantity}" name="orderItems[${orderItem_index}].price" class="orderItem_price" value="${orderItem.price}" />
						[#if orderItem.isGift]
						[#elseif orderItem.name=="卫浴散热器" ]
						[#elseif orderItem.name=="散热器" ]
						[#elseif orderItem.name=="电热执行器" || orderItem.name=="温控面板" ]
						[#elseif orderItem.name=="提升泵" ]
						[#elseif orderItem.name=="控制器" ]
						[#else]
							<input type="hidden" class="orderItemQuantity" name="orderItems[${orderItem_index}].quantity" value="${orderItem.quantity}" />
						[/#if]
						<input type="hidden" name="orderItems[${orderItem_index}].differencePrice" value="${orderItem.differencePrice}" />
						<input type="hidden" name="orderItems[${orderItem_index}].weight" value="${orderItem.weight}" />
						<input type="hidden" class="checkSchemeIsGift" name="orderItems[${orderItem_index}].isGift" value="${orderItem.isGift}" />
						<input type="hidden" class="coefficient"  value="${orderItem.coefficient}" /><!-- 系数 -->
						<input type="hidden" class="iniQuantity"  value="${orderItem.iniQuantity}" /><!-- 初始数量 -->
						<input type="hidden" class="schemeProductPrice" value="${orderItem.schemeProductPrice}" /><!--初始单价-->
						${orderItem.sn}
					</td>
					<td width="400">
						<span title="${orderItem.fullName}" class="order_scheme_product_name">${abbreviate(orderItem.fullName, 50)}</span>
						[#if orderItem.isGift]
							<span class="red">[${message("admin.order.gift")}]</span>
						[/#if]
					</td>
					<td calss="brandName">
						${orderItem.schemeProductBrand}
					</td>
					<td calss="specificationValue">
						${orderItem.schemeProductSpecificationValue}
					</td>
					<td>
						[#if orderItem.isGift||orderItem.name=="卫浴散热器"||orderItem.name=="散热器"||orderItem.name=="电热执行器" || orderItem.name=="温控面板"||orderItem.name=="提升泵"||orderItem.name=="控制器"]
							[#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4]
								<input type="text" name="orderItems[${orderItem_index}].quantity" class="text orderItemQuantity" value="${orderItem.quantity}" maxlength="4" style="width: 30px;" />
							[#else]
								<input type="hidden" name="orderItems[${orderItem_index}].quantity" class="text orderItemQuantity" value="${orderItem.quantity}" maxlength="4" style="width: 30px;" />
								${orderItem.quantity}
							[/#if]
						[/#if]
					</td>
					<td class="shopSchemeProductSn">
						${orderItem.shopSchemeProductSn}
					</td>
					<td class="shopSchemeProductName">
						[#if orderItem.isGift]
						[#else]
							${orderItem.shopSchemeProductName}
						[/#if]
					</td>
					<td class="shopSchemeProductBrand">
						${orderItem.shopSchemeProductBrand}
					</td>
					<td class="shopSchemeProductSpecificationValue">
						${orderItem.shopSchemeProductSpecificationValue}
					</td>
					<td class="differencePrice">
						[#if orderItem.coefficient??]
							${currency(orderItem.differencePrice*(order.schemeArea+order.shopSchemeArea)*orderItem.coefficient, true)}
						[#else]
							${currency(orderItem.differencePrice, true)}
						[/#if]
					</td>
					<td>
						[#if orderItem.isGift]
							<a href="javascript:;"[#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4]class="deleteOrderItem"[/#if]>[${message("admin.common.delete")}]</a>
						[#else]
							<a href="javascript:;" schemeNameId="${orderItem.schemeNameId}" editId="${orderItem.id}" [#if order.schemeStatus==1 || order.schemeStatus==3 || order.schemeStatus==4] onclick="superEditShow(this)"[/#if] >[${message("admin.common.edit")}]</a>
						[/#if]
					</td>
				</tr>
			[/#list]
		</table>
		<table class="input">
			<tr>
				<th>
					&nbsp;
				</th>
				<td>
					[#if order.schemeStatus==1||order.schemeStatus==3||order.schemeStatus==4]
						[@shiro.hasPermission name = "admin:orderAdjust"]
							<input type="submit" onclick="return checkAmountScheme()" class="button" value="${message("admin.common.submit")}" />
						[/@shiro.hasPermission]
					[#elseif order.schemeStatus==5]
						[@shiro.hasPermission name = "admin:orderAudit"]
						<input type="submit" class="button" value="${message("admin.common.submit")}" />
						[/@shiro.hasPermission]
					[#elseif order.schemeStatus==7]
						[@shiro.hasPermission name = "admin:tailPayment"]
						<input type="submit" class="button" value="${message("admin.common.submit")}" />
						[/@shiro.hasPermission]
					[#elseif order.schemeStatus==6]
						[@shiro.hasPermission name = "admin:tailPayment"]
						<input type="submit" class="button" value="${message("admin.common.submit")}" />
						[/@shiro.hasPermission]
					[/#if]
					<input type="button" undisabled=false class="button" value="${message("admin.common.back")}" onclick="location.href='listScheme.jhtml'" />
				</td>
			</tr>
		</table>
	</form>
	<!--选择主材弹出层-->
		<div class="c-pop-window"  id="Check_See">
			<div class="c-pop-content" id="Check_See2s">
				<h2>选择主材产品</h2>
				<img class="close" src="${base}/resources/admin/images/x.png" onClick="colseSchemeProduct();">
				<div class="c-scrollBox">
					<table class="params_table_class">
						<tr>
							<td>编码</td>
							<td><input id="params_table_scheme_sn" type="text" class="text" name="sn"/></td>
							<td>名称</td>
							<td><input id="params_table_scheme_name" type="text" class="text" name="name"/></td>
							<td><input type="button" onclick="findSchemeProduct_scheme()"  class="button" value="查询"/></td>
						</tr>
					</table>
					<table class="baseTable-border" id="schemeproductTab">
						<thead>
							<tr>
								<th style="width:5%;">
									<span>&nbsp;</span>
								</th>
								<th style="width:15%;">
									<span>编码</span>
								</th>
								<th>
									<span>名称</span>
								</th>
								<th>
									<span>品牌</span>
								</th>
								<th>
									<span>规格</span>
								</th>
								<th>
									<span>分类</span>
								</th>
								<th>
									<span>价格</span>
								</th>
							</tr>
						</thead>
						<tbody>
							
						</tbody>
					</table>
				</div>	
		      	<div style="text-align: center;">
		      		<a href="JavaScript:;" class="button ensure" onClick="schemeOrderEdit();">确定</a>
		      	</div>
		    </div>
			<div class="c-cover"></div>
		</div>
		<div class="c-pop-window"  id="Check_See_scheme">
			<div class="c-pop-content" id="Check_See2s_scheme">
				<h2>选择赠品</h2>
				<img class="close" src="${base}/resources/admin/images/x.png" onClick="colseSchemeProductGift();">
				<div class="c-scrollBox">
					<table class="params_table_class">
						<tr>
							<td>编码</td>
							<td><input id="params_table_class_sn" type="text" class="text" name="sn"/></td>
							<td>名称</td>
							<td><input id="params_table_class_name" type="text" class="text" name="name"/></td>
							<td><input type="button" onclick="addGiftProductScheme()" class="button" value="查询"/></td>
						</tr>
					</table>
					
					<table class="baseTable-border" id="schemeproductTab_scheme">
						<thead>
							<tr>
								<th style="width:5%;">
									<span>&nbsp;</span>
								</th>
								<th style="width:15%;">
									<span>编码</span>
								</th>
								<th>
									<span>名称</span>
								</th>
								<th>
									<span>品牌</span>
								</th>
								<th>
									<span>价格</span>
								</th>
							</tr>
						</thead>
						<tbody>
							
						</tbody>
					</table>
				</div>	
		      	<div style="text-align: center;">
		      		<a href="JavaScript:;" class="button ensure" onClick="appendGiftProduct();">确定</a>
		      	</div>
		    </div>
			<div class="c-cover"></div>
		</div>
</body>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.tools.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.validate.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.lSelect.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/common.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/input.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/scheme.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/map.js"></script>
<script type="text/javascript">
var orderItemIndex = ${order.orderItems?size};
var init_order_scheme_amount=${order.amount};

var ini_order_status=${order.schemeStatus};//订单状态
var ini_order_item_amount=${order.price};//订单项金
var ini_order_area=${order.schemeArea};//方案面积
var ini_order_install_cost=${order.installCost};//方案安装费
var ini_order_auxiliary_unit_price=${order.auxiliaryUnitPrice};//辅材价格
var ini_order_otherMoney=${order.otherMoney};//当前订单附加金额
var ini_order_freight=${order.freight};//运费
var ini_scheme_type=${order.schemeType};//方案类型
var fixed_scheme_type_ZNKT=105;//智能空调
var fixed_scheme_type_ZNNQ=14;//智能暖气
var temp_order_difference=0;
function calculate_scheme(){
	if(typeof difference=="undefined"){
		difference=0;
	}
	var new_order_shop_area=$("#order_scheme_shop_area").val();//获取已调整面积
	var new_order_promotionDiscountScheme=$("#order_promotionDiscountScheme").val();//获取文本优惠金额
	var new_order_freight=$("#order_freight").val();//文本运费
	var new_order_amout_price =calculatedTotal();//订单项总额
	var new_order_install_cost=0.00;//安装费
	var new_order_auxiliary_unit_price=0.00;//辅材
	var new_order_shop_should_pay=0.00;//门店应支付
	var new_other_money=$("#otherMoneyCheck").val();
	var new_total_area=0;
	if(!new_order_shop_area){
		new_order_shop_area=0;
	}
	if(!new_order_promotionDiscountScheme){
		new_order_promotionDiscountScheme=0;
	}
	
	new_order_amout_price=parseFloat(new_order_amout_price)-parseFloat(new_order_promotionDiscountScheme);//订单总额减去促销折扣金额
	
	new_total_area=Number(new_order_shop_area)+Number(ini_order_area);//总面积
	if(ini_scheme_type!=fixed_scheme_type_ZNKT){//计算出智能空调之外的安装费+辅材费
		var temp1=parseFloat(new_total_area)*parseFloat(ini_order_install_cost);
		var temp2=parseFloat(new_total_area)*parseFloat(ini_order_auxiliary_unit_price);
		new_order_amout_price=parseFloat(new_order_amout_price)+parseFloat(temp1)+parseFloat(temp2);
	}else{
		var ini_outNumber=$("#order_outNumber").val();
		var ini_inNumber=$("#order_inNumber").val();
		if(!ini_outNumber){
			ini_outNumber=0;
		}
		if(!ini_inNumber){
			ini_inNumber=0;
		}
		var new_total_number=Number(ini_outNumber)+Number(ini_inNumber);
		var temp1=parseFloat(new_total_number)*parseFloat(ini_order_install_cost);
		var temp2=parseFloat(ini_inNumber)*parseFloat(ini_order_auxiliary_unit_price);
		new_order_amout_price=parseFloat(new_order_amout_price)+parseFloat(temp1)+parseFloat(temp2);
	}
	
	if(!new_other_money){
		new_other_money=0;
	}
	new_order_amout_price=parseFloat(new_order_amout_price)+parseFloat(new_other_money);//计算附加金额
	
	if(new_order_freight){//计算运费
		new_order_amout_price=parseFloat(new_order_amout_price)+parseFloat(new_order_freight);
	}
	if(temp_order_difference){//计算差额
		new_order_amout_price=parseFloat(new_order_amout_price)+parseFloat(temp_order_difference);//获取当前订单总价
	}
	
	
	$("#order_amount_td").html("￥"+new_order_amout_price.toFixed(2));//设置 订单总金额
	var alreadPaid =parseFloat($("#alreadyPaid").text().replace("￥",""));
	$("#surplusMoney").text("￥"+(new_order_amout_price - alreadPaid ).toFixed(2));
	init_order_scheme_amount=parseFloat(new_order_amout_price)+parseFloat(new_order_promotionDiscountScheme);
	var temp=parseFloat(init_order_scheme_amount)*parseFloat(0.46);//订单金额的5%
	var temp1=parseFloat($("#order_promotionDiscountScheme").val());//当前优惠金额
	temp1=parseFloat(temp1.toFixed(2));
	temp=parseFloat(temp.toFixed(2));
	if(temp1>temp){
		$.message("warn","优惠金额不能超过订单金额的46%");
		return false;
	}
}
//计算主材总价
function calculatedTotal(){
	var total=0;
	$("#orderItemTable .orderItemTr").each(function(i,the){
		total +=calculatedRowPrice($(the));
	});
	return total;
}
function checkAmountScheme(){
	var temp=parseFloat(init_order_scheme_amount)*parseFloat(0.46);//订单金额的5%
	var temp1=parseFloat($("#order_promotionDiscountScheme").val());//当前优惠金额
	temp1=parseFloat(temp1.toFixed(2));
	temp=parseFloat(temp.toFixed(2));
	var isTehui = $("#order_isTehui").val();//特惠
	var isChange = $("#order_isChange").val();//
	if(temp1>temp){
		$.message("warn","优惠金额不能超过订单金额的46%");
		return false;
	}
	var beginArea = ${order.beginArea};
	var endArea = ${order.endArea};
	var isTehui = $("#order_isTehui").val();//特惠
	var isChange = $("#order_isChange").val();//
	var measureArea = $("#order_scheme_shop_area").val();
	if(!measureArea){
		measureArea=0;
	}
	var totalArea =Number(measureArea)+Number(${order.schemeArea});
	//特惠方案或固定方案
	if(isTehui || isChange){
		if(totalArea<beginArea || totalArea>endArea){
			$.message("warn","范围不能小于"+beginArea+"也不能大于"+endArea);
			return false;
		}
	}
}
var schemeMap=new Map();
$().ready(function() {
	
	var $inputForm = $("#inputForm");
	var $input = $("#inputForm :input:not(#productSn)");
	var $amount = $("#amount");
	var $weight = $("#weight");
	var $quantity = $("#quantity");
	var $isInvoice = $("#isInvoice");
	var $invoiceTitle = $("#invoiceTitle");
	var $tax = $("#tax");
	var $areaId = $("#areaId");
	var $orderItemTable = $("#orderItemTable");
	var $deleteOrderItem = $("#orderItemTable a.deleteOrderItem");
	var $productSn = $("#productSn");
	var $schemeSn = $("#schemeSn");
	var $addOrderItem = $("#addOrderItem");
	var isLocked = false;
	var timeouts = {};
	[@flash_message /]
	// 初始值
	$input.each(function() {
		var $this = $(this);
		$this.data("value", $this.val());
	});
	
	// 地区选择
	$areaId.lSelect({
		url: "${base}/admin/common/area.jhtml"
	});
	
	
	var checkBoxValIsTemperature=$("#order_isTemperature").val();
	var checkBoxValIsDissipate=$("#order_isDissipate").val();
	var checkBoxValIsPromote=$("#order_isPromote").val();
	var checkBoxValIsController=$("#order_isController").val();
	
	if((checkBoxValIsTemperature==true||checkBoxValIsTemperature=="true")&&(checkBoxValIsDissipate==false||checkBoxValIsDissipate=="false")){
		$("#orderItemTable").find(".isTemperatureTr").each(function(){
			$(this).css({"display":"table-row"});
		});
	}else if((checkBoxValIsTemperature==false||checkBoxValIsTemperature=="false")&&(checkBoxValIsDissipate==true||checkBoxValIsDissipate=="true")){
		$("#orderItemTable").find(".isDissipateTr").each(function(){
			$(this).css({"display":"table-row"});
		});
	}else if((checkBoxValIsController==false||checkBoxValIsController=="false")&&(checkBoxValIsPromote==true||checkBoxValIsPromote=="true")){
		$("#orderItemTable").find(".isPromoteTr").each(function(){
			$(this).css({"display":"table-row"});
		});
	}else if((checkBoxValIsPromote==false||checkBoxValIsPromote=="false")&&(checkBoxValIsController==true||checkBoxValIsController=="true")){
		$("#orderItemTable").find(".isControllerTr").each(function(){
			$(this).css({"display":"table-row"});
		});
	}else if((checkBoxValIsPromote==true||checkBoxValIsPromote=="true")&&(checkBoxValIsController==true||checkBoxValIsController=="true")){
		$("#orderItemTable").find(".isControllerTr").each(function(){
			$(this).css({"display":"table-row"});
		});
		$("#orderItemTable").find(".isPromoteTr").each(function(){
			$(this).css({"display":"table-row"});
		});
	}else if ((checkBoxValIsTemperature==true||checkBoxValIsTemperature=="true")&&(checkBoxValIsDissipate==true||checkBoxValIsDissipate=="true")){
		$("#orderItemTable").find(".isTemperatureTr").each(function(){
			$(this).css({"display":"table-row"});
		});
		$("#orderItemTable").find(".isDissipateTr").each(function(){
			$(this).css({"display":"table-row"});
		});
	}else if((checkBoxValIsTemperature==false||checkBoxValIsTemperature=="false")&&(checkBoxValIsDissipate==false||checkBoxValIsDissipate=="false")){
	
	}else if((checkBoxValIsController==false||checkBoxValIsController=="false")&&(checkBoxValIsPromote==false||checkBoxValIsPromote=="false")){
	
	}else{
		$("#orderItemTable").find(".orderItemTr").each(function(){
			$(this).css({"display":"table-row"});
		});
	}
	// 检查锁定
	function checkLock() {
		if (!isLocked) {
			$.ajax({
				url: "check_lock.jhtml",
				type: "POST",
				data: {id: ${order.id}},
				dataType: "json",
				cache: false,
				success: function(message) {
					if (message.type != "success") {
						$.message(message);
						$inputForm.find(":input:not(#backButton), #orderItemTable a.deleteOrderItem").prop("disabled", true);
						isLocked = true;
					}
				}
			});
		}
	}
	
	// 检查锁定
	checkLock();
	setInterval(function() {
		checkLock();
	}, 10000);
	
	// 开据发票
	$isInvoice.click(function() {
		if ($(this).prop("checked")) {
			$invoiceTitle.prop("disabled", false);
			$tax.prop("disabled", false);
		} else {
			$invoiceTitle.prop("disabled", true);
			$tax.prop("disabled", true);
		}
	});
	
	// 计算
	$("#otherMoneyCheck").bind("input propertychange change", function(event) {
		if (event.type != "propertychange" || event.originalEvent.propertyName == "value") {
			calculate_scheme();
		}
	});
	$(".orderItemQuantity").bind("input propertychange change", function(event) {
		if (event.type != "propertychange" || event.originalEvent.propertyName == "value") {
			calculate_scheme();
		}
	});
	//面积限制
	$("#order_scheme_shop_area").bind("input propertychange change", function(event) {
		var beginArea = ${order.beginArea}
		var endArea = ${order.endArea}
		var measureArea = $("#order_scheme_shop_area").val();
		if(!measureArea){
			measureArea=0;
		}
		var totalArea =Number(measureArea)+Number(${order.schemeArea});
		var isTehui = $("#order_isTehui").val();//特惠
		var isChange = $("#order_isChange").val();//
		//特惠方案或固定方案
		if(isTehui || isChange){
			if(totalArea<beginArea || totalArea>endArea){
				$.message("warn","范围不能小于"+beginArea+"也不能大于"+endArea);
			}
		}
		
		if (event.type != "propertychange" || event.originalEvent.propertyName == "value") {
			calculate_scheme();
		}
	});
	// 计算
	$("#addOrderItem_scheme").click(function(){
		superShow();
	});
	$("#addOrderItem_scheme_gift").click(function(){
		addGiftProductScheme();
	});
	// 添加订单项
	$addOrderItem.click(function() {
		var productSn = $.trim($schemeSn.val());
		if (productSn == "") {
			$.message("warn", "${message("admin.order.productSnRequired")}");
			return false;
		}
		var repeat = false;
		$("#inputForm input.orderItemSn").each(function() {
			if ($(this).val() == productSn) {
				repeat = true;
				return false;
			}
		});
		if (repeat) {
			$.message("warn", "${message("admin.order.productSnExist")}");
			return false;
		}
		
		$.ajax({
			url: "order_item_add_scheme.jhtml",
			type: "POST",
			data: {schemeSn: $schemeSn.val()},
			dataType: "json",
			success: function(data) {
				if (data.message.type == "success") {
					[@compress single_line = true]
						var $tr = $(
						'<tr class="orderItemTr">
							<td>
								<input type="hidden" name="orderItems[' + orderItemIndex + '].sn" class="orderItemSn" value="' + data.sn + '" \/>
								<input type="hidden" name="orderItems[' + orderItemIndex + '].price" value="' + data.price + '" \/>
								<input type="hidden" name="orderItems[' + orderItemIndex + '].quantity" value="' + data.quantity + '" \/>
								<input type="hidden" name="orderItems[' + orderItemIndex + '].differencePrice" value="' +data.differencePrice+'" \/>
								<input type="hidden" name="orderItems[' + orderItemIndex + '].isGift" value="' + data.isGift + '" \/>
								<input type="hidden" name="orderItems[' + orderItemIndex + '].weight" value="' + (data.weight != null ? data.weight : '') + '" \/>
								' + data.sn + '
							<\/td>
							<td width="400">
								<span title="' + data.fullName + '">' + data.fullName.substring(0, 50) + '<\/span>
								' + (data.isGift ? '<span class="red">[${message("admin.order.gift")}]<\/span>' : '') + '
							<\/td>
							<td>
								' + data.brandName + '
							<\/td>
							<td>
								' + data.specificationValue + '
							<\/td>
							<td>
								
							<\/td>
							<td>
								￥0.00
							<\/td>
							<td>
								<a href="javascript:;" class="deleteOrderItem">[${message("admin.common.delete")}]<\/a>
							<\/td>
						<\/tr>');
					[/@compress]
					$tr.appendTo($orderItemTable).find(":text").each(function() {
						var $this = $(this);
						$this.data("value", $this.val());
					}).bind("input propertychange change", function(event) {
						if (event.type != "propertychange" || event.originalEvent.propertyName == "value") {
							calculate($(this));
						}
					});
					orderItemIndex ++;
				} else {
					$.message(data.message);
				}
			}
		});
	});
	// 删除订单项
	$deleteOrderItem.live("click", function() {
		var $this = $(this);
		if ($orderItemTable.find("tr.orderItemTr").size() <= 1) {
			$.message("warn", "${message("admin.common.deleteAllNotAllowed")}");
		} else {
			$this.closest("tr").find(":text").each(function() {
				var name = $(this).attr("name");
				clearTimeout(timeouts[name]);
			});
			$this.closest("tr").remove();
			calculate_scheme_new_add();
		}
	});
	
	$.validator.addClassRules({
		orderItemPrice: {
			required: true,
			min: 0,
			decimal: {
				integer: 12,
				fraction: ${setting.priceScale}
			}
		},
		otherMoney: {
			required: true,
			min: 0,
			decimal: {
				integer: 12,
				fraction: ${setting.priceScale}
			}
		}
	});
	//offsetAmount: {
	//			required: true,
	//			number: true,
	//			decimal: {
	//				integer: 12,
	//				fraction: ${setting.priceScale}
	//			}
	//		},
	// 表单验证
	$inputForm.validate({
		rules: {
			point: {
				required: true,
				digits: true
			},
			shopSchemeArea: {
				required: false,
				number: true,
			},
			percentPrice: {
				required: true,
				number: true,
				min: 0.00,
			},
			freight: {
				required: true,
				min: 0,
				decimal: {
					integer: 12,
					fraction: ${setting.priceScale}
				}
			},
			promotionDiscountScheme: {
				required: false,
				min: 0,
				decimal: {
					integer: 12,
					fraction: ${setting.priceScale}
				}
			},
			paymentMethodId: "required",
			shippingMethodId: "required",
			invoiceTitle: "required",
			tax: {
				required: true,
				min: 0,
				decimal: {
					integer: 12,
					fraction: ${setting.priceScale}
				}
			},
			contract:"required",
			consignee: "required",
			areaId: "required",
			address: "required",
			zipCode: "required",
			phone: "required"
		}
		//,
		//showErrors:function(errorMap, errorList){
		//	var msg = "";
		//	$.each(errorList, function(i, v) {  
		//    	msg += (v.message + "\r\n");  
		//    });  
		//    if (msg != "")  
     	//	$.message("warn","请检查必填项！！"); 
		//}
	});
	$($("#areaId").parent()).find("select").each(function(){
		$(this).attr("disabled","disabled");
	});
	

});
function checkBoxScheme(obj){
	var checkVal=$(obj).val();
	var tempId=$(obj).attr("id");
	if(checkVal=="true"||checkVal==true){
		$(obj).removeAttr("checked");
		$(obj).val("false");
		//   
		if("order_isTemperature"==tempId){
			$("#orderItemTable").find(".isTemperatureTr").each(function(i,the){
				$(this).hide();
				$(this).find(".orderItemQuantity").val(0);
				calculatedRowPrice($(the));
			});
		}else if("order_isDissipate"==tempId){
			$("#orderItemTable").find(".isDissipateTr").each(function(i,the){
				$(this).hide();
				$(this).find(".orderItemQuantity").val(0);
				calculatedRowPrice($(the));
			});
		}else if("order_isPromote"==tempId){
			$("#orderItemTable").find(".isPromoteTr").each(function(i,the){
				$(this).hide();
				$(this).find(".orderItemQuantity").val(0);
				calculatedRowPrice($(the));
			});
		}else if("order_isController"==tempId){
			$("#orderItemTable").find(".isControllerTr").each(function(i,the){
				$(this).hide();
				$(this).find(".orderItemQuantity").val(0);
				calculatedRowPrice($(the));
			});
		}
	}else{
		$(obj).attr("checked","checked");
		$(obj).val("true");
		if("order_isTemperature"==tempId){
			$("#orderItemTable").find(".isTemperatureTr").each(function(){
				$(this).css({"display":"table-row"});
			});
		}else if("order_isDissipate"==tempId){
			$("#orderItemTable").find(".isDissipateTr").each(function(){
				$(this).css({"display":"table-row"});
			});
		}else if("order_isPromote"==tempId){
			$("#orderItemTable").find(".isPromoteTr").each(function(){
				$(this).css({"display":"table-row"});
			});
		}else if("order_isController"==tempId){
			$("#orderItemTable").find(".isControllerTr").each(function(){
				$(this).css({"display":"table-row"});
			});
		}
	}
}
function addOrderItemScheme(schemeSn){
		var schemeSn_params = $.trim(schemeSn);
		if (schemeSn_params == "") {
			$.message("warn", "${message("admin.order.productSnRequired")}");
			return false;
		}
		var repeat = false;
		$("#inputForm input.orderItemSn").each(function() {
			if ($(this).val() == schemeSn_params) {
				repeat = true;
				return false;
			}
		});
		if (repeat) {
			$.message("warn", "${message("admin.order.productSnExist")}");
			return false;
		}
		var orderId=$("#orderId").val();
		$.ajax({
			url: "order_item_add_scheme.jhtml",
			type: "POST",
			data: {schemeSn: schemeSn_params,orderId: orderId},
			dataType: "json",
			success: function(data) {
				if (data.message.type == "success") {
					var html="";
					$(data).each(function(i){
						var weight="0";
						var isGift="false";
						if(data.weight!=null){
							weight=data.weight;
						}
						if(data.isGift!=null){
							isGift=data.isGift;
						}
						var fullName=data.fullName.substring(0, 50);
						var inputTD="";
						if (data.isGift==true||data.isGift=="true"||data.name!="卫浴散热器"||data.name!="散热器" ||data.name!="电热执行器" || data.name=="温控面板"|| data.name=="提升泵"||data.name=="控制器"){
							inputTD="<input type='hidden' name='orderItems[" + orderItemIndex + "].quantity' value='"+data.quantity+"' />";
						}
						html+="<tr class='orderItemTr'><td>";
						html+="<input type='hidden' name='orderItems["+orderItemIndex+"].sn' class='orderItemSn' value='"+data.sn+"'/>";
						html+="<input type='hidden' class='newAddSchemeProduct' name='orderItems["+orderItemIndex+"].price' value='"+data.price+"'/>";
						html+="<input type='hidden' class='checkIsGit' name='orderItems["+orderItemIndex+"].isGift' value='"+isGift+"'/>";
						html+="<input type='hidden' name='orderItems["+orderItemIndex+"].weight' value='"+weight+"'/>";
						html+="<input type='hidden' name='orderItems["+orderItemIndex+"].differencePrice' value='"+data.differencePrice+"'/>";
						html+="<input type='hidden' class='coefficient' value='"+data.coefficient+"'/>";
						html+=inputTD;
						html+=data.sn;
						html+="</td>";
						html+="<td width='400'>";
						html+="<span title='"+data.fullName+"' class='order_scheme_product_name'>"+fullName+"</span>";
						if(data.isGift==true||data.isGift=="true"){
							html+="<span class='red'>[赠品]</span>";
						}
						html+="</td><td>";
						html+=data.brandName;
						html+="</td><td>";
						html+=data.specificationValue;
						html+="</td><td>";
						if(data.name=="卫浴散热器"||data.name=="散热器"||data.name=="电热执行器" || data.name=="温控面板"||data.name=="提升泵"||data.name=="控制器"){
							html+="<input type='text' name='orderItems['"+orderItemIndex+"'].quantity' class='text orderItemQuantity' value='1' maxlength='4' style='width:30px;'/>";
						}
						html+="</td><td></td><td></td><td></td><td></td><td>￥0.00</td><td>";
						html+="<a href='javascript:;' class='deleteOrderItem'>[删除]</a></td>";
					});
					$(html).appendTo($("#orderItemTable")).find(":text").each(function() {
						var $this = $(this);
						$this.data("value", $this.val());
					}).bind("input propertychange change", function(event) {
						if (event.type != "propertychange" || event.originalEvent.propertyName == "value") {
							calculate_scheme_new_add();
						}
					});
					orderItemIndex ++;
				calculate_scheme_new_add();
				} else {
					$.message(data.message);
				}
			}
		});
	}
	function Trim(str,is_global)
        {
            var result;
            result = str.replace(/(^\s+)|(\s+$)/g,"");
            if(is_global.toLowerCase()=="g")
            {
                result = result.replace(/\s/g,"");
             }
            return result;
}
function calculate_scheme_new_add(){
	var total=0;
	$("#orderItemTable").find(".orderItemTr").each(function(){
			var tempPrice=0;
			var $this=$(this);
			var temp=$($this).find(".newAddSchemeProduct").val();	//新增价格
			var quantity =$($this).find(".orderItemQuantity").val();//数量
			if(!quantity){
				quantity=1;
			}
			if(!temp){
				temp=0;
			}
			var tempEdit=$($this).find(".differencePrice").text();//编辑后差价
			tempEdit=Trim(tempEdit,"g");
			//var orderItemSchemeProductName=$($this).find(".order_scheme_product_name").text();
			//orderItemSchemeProductName=Trim(orderItemSchemeProductName,"g");
			if(!tempEdit&&!$.trim(tempEdit)){
				tempEdit=0;
			}else{
				var isSub=tempEdit.substring(0,1);//差价
				if(isSub=="￥"){
					tempEdit=tempEdit.substring(1,tempEdit.length);
				}
			}
			total=parseFloat(total)+parseFloat(temp);
			var isCalculateAttr=$($this).find(".checkSchemeId").attr("iscalculate");
			if(isCalculateAttr==true||isCalculateAttr=="true"){
				total=parseFloat(total)+parseFloat(tempEdit);
			}
	});
	temp_order_difference=total;
	calculate_scheme(total);//计算价格
}
function addOrderItemScheme_gift(productSn){
		var schemeSn_params = $.trim(productSn);
		if (schemeSn_params == "") {
			$.message("warn", "${message("admin.order.productSnRequired")}");
			return false;
		}
		var repeat = false;
		$("#inputForm input.orderItemSn").each(function() {
			if ($(this).val() == schemeSn_params) {
				repeat = true;
				return false;
			}
		});
		if (repeat) {
			$.message("warn", "${message("admin.order.productSnExist")}");
			return false;
		}
		
		$.ajax({
			url: "order_item_add.jhtml",
			type: "POST",
			data: {productSn: schemeSn_params},
			dataType: "json",
			success: function(data) {
				if (data.message.type == "success") {
					var html="";
					$(data).each(function(i){
						var weight="0";
						var isGift="true";
						if(data.weight!=null){
							weight=data.weight;
						}
						if(data.isGift!=null){
							isGift=data.isGift;
						}
						var fullName=data.fullName.substring(0, 50);
						html+="<tr class='orderItemTr'>";
						html+="<td>";
						html+="<input type='hidden' name='orderItems["+orderItemIndex+"].sn' class='orderItemSn' value='"+data.sn+"'/>";
						html+="<input type='hidden' name='orderItems["+orderItemIndex+"].price' value='"+data.price+"'/>";
						html+="<input type='hidden' class='checkIsGit' name='orderItems["+orderItemIndex+"].isGift' value='"+isGift+"'/>";
						html+="<input type='hidden' name='orderItems["+orderItemIndex+"].weight' value='"+weight+"'/>";
						html+=data.sn;
						html+="</td>";
						html+="<td width='100'>";
						html+="<span title='"+data.fullName+"' class='order_scheme_product_name'>"+fullName+"</span>";
						if(data.isGift==true||data.isGift=="true"){
							html+="<span class='red'>[赠品]</span>";
						}
						html+="</td>";
						html+="<td>";
						html+=data.brandName;
						html+="</td>";
						html+="<td>";
						html+="</td>";
						html+="<td>";
						html+="<input type='text' name='orderItems["+orderItemIndex+"].quantity' class='text orderItemQuantity' value='1' maxlength='4' style='width:30px;'/>";
						html+="</td>";
						html+="<td>";
						html+="</td>";
						html+="<td>";
						html+="</td>";
						html+="<td>";
						html+="</td>";
						html+="<td>";
						html+="</td>";
						html+="<td>";
						html+="￥0.00";
						html+="</td>";
						html+="<td>";
						html+="<a href='javascript:;' class='deleteOrderItem'>[删除]</a>"
						html+="</td>";
					});
					$(html).appendTo($("#orderItemTable")).find(":text").each(function() {
						var $this = $(this);
						$this.data("value", $this.val());
					}).bind("input propertychange change", function(event) {
						if (event.type != "propertychange" || event.originalEvent.propertyName == "value") {
						}
					});
					orderItemIndex ++;
				} else {
					$.message(data.message);
				}
			}
		});
	}
//计算当前行价格
function calculatedRowPrice(the){
	var $thisRow =the; 
	var total=0;
	if($thisRow.css("display") =="none"){
		return 0;
	}
	var differe=0;//差价
	var coefficient;//系数
	var area =ini_order_area+(parseInt($("#order_scheme_shop_area").val()) || 0);
	var iniPrice =parseFloat($thisRow.find(".schemeProductPrice").val() || 0);//原价
	var shopSchemeProductSn =$thisRow.find(".shopSchemeProductSn").text().replace(/\s+/g,"");
	if($thisRow.find(".coefficient").val()){
		coefficient =parseFloat($thisRow.find(".coefficient").val()) || 0 ;//系数
		if(!shopSchemeProductSn){
			total +=iniPrice*coefficient*area;
		}else{
			var newPrice =parseFloat($thisRow.find(".differencePrice").attr("data_newPrice")) || 0;
			total +=newPrice*coefficient*area;
			//计算差价
			differe =newPrice*coefficient*area-iniPrice*coefficient*area;
		}
	}else{//没有系数
		if($thisRow.find(".orderItemQuantity").length =0){//判断编辑数量input
			if(!shopSchemeProductSn){//判断是否更换主材
				total +=iniPrice;
			}else{
				var newPrice =parseFloat($thisRow.find(".differencePrice").attr("data_newPrice")) || 0;
				total +=newPrice;
				differe =newPrice-iniPrice;
			}
		}else{//可编辑数量
			var quantity =parseInt($thisRow.find(".orderItemQuantity").val()) || 0;//编辑数量
			var iniQuantity =parseInt($thisRow.find(".iniQuantity").val()) || 0;
			if(!shopSchemeProductSn){
				total +=iniPrice*quantity;
				differe =iniPrice*quantity-iniPrice*iniQuantity;
			}else{	
				var newPrice=(parseFloat($thisRow.find(".differencePrice").attr("data_newPrice")) || 0);
				total += newPrice*quantity;
				//iniQuantity
				differe =newPrice*quantity-iniPrice*iniQuantity;
			}
		}
	}
	$thisRow.find(".differencePrice").text("￥"+differe.toFixed(2));//设置差价
	return total;
}
</script>
</html>